new Vue({
  el: '#login',
  data: function () {
    return {
      logining: false,     //是否正在登录中……
      ruleForm: {
        userNum: 'admin',
        password: '123456',
        checked: true
      },
      rules: {
        userNum: [
          { required: true, message: '请输入账号', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ],
      }
    }
  },
  mounted: function () {
    this.userInfoAuto();
  },
  methods: {
    userInfoAuto() { //是否曾经记住密码，自动填入
      var userInfo = JSON.parse(sessionStorage.getItem('userInfo'));
      if (userInfo) {
        this.ruleForm.userNum = userInfo.username;
        this.ruleForm.password = userInfo.password;
      }
    },
    userInfoRem(loginParams) {  //是否保存密码
      //存入缓存，作为登录状态的判断  推荐：cookie 加密后存储 
      //  console.log(this.ruleForm.checked);
      if (this.ruleForm.checked) {
        console.log("存入缓存,记住密码");
        sessionStorage.setItem("userInfo", JSON.stringify(loginParams));
      } else {
        console.log("不存入缓存,不记住密码");
      }
    },
    handleSubmit2() {    //验证登录
      var _this = this;
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          this.logining = true;
          var loginParams = { username: this.ruleForm.userNum, password: this.ruleForm.password };
          setTimeout(function(){
            window.location.href="../index/index.html";
          },1500);
          //请求数据验证用户名
          // requestLogin(loginParams).then(data => {
          //   this.logining = false;
          //   let { msg, code, user } = data;
          //   console.log(JSON.stringify(data));
          //   if (code !== 200) {
          //     this.$message({ //提示登录状态
          //       message: msg,
          //       type: 'error'
          //     });
          //   } else {
          //     _this.userInfoRem(loginParams);  //判断是否保存密码  
          //     this.$message({ //提示登录状态
          //       message: msg,
          //       type: 'success',
          //       duration: 500,
          //       onClose: function () {
          //         _this.$router.push({ path: '/' });
          //       }
          //     });
          //   }
          // })
        } else {
          console.log('error submit!');
          return false;
        }


        
      });
    }
  }
});